package com.huawei.lynnbit.tool.cocos.processor;

import com.huawei.lynnbit.tool.cocos.config.game.GameConfig;
import com.huawei.lynnbit.tool.cocos.config.game.task.Task;
import com.huawei.lynnbit.tool.cocos.processor.leaf.LeafProcessorFactory;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

public class CompositeProcessor implements Processor {
    private List<Processor> processorList;


    public CompositeProcessor() {
        processorList = new ArrayList<>();
    }

    public CompositeProcessor(List<Task> taskList, GameConfig gameConfig) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        processorList = new ArrayList<>();
        for (Task task : taskList) {
            processorList.add(LeafProcessorFactory.newInstance(task, gameConfig));
        }
    }

    @Override
    public void addProcessor(Processor processor) {
        processorList.add(processor);
    }

    @Override
    public void process() throws Exception {
        for (Processor processor : processorList) {
            processor.process();
        }
    }
}
